from flask import Blueprint, request
from service.user_service import UserService
from utils.ResultUtil import Response
from model.User import User

test = Blueprint("test", __name__, url_prefix="/test")


@test.route('/list', methods=['GET'])
def user_list():
    return Response().success(UserService().list())


@test.route('/fingByName/<string:name>', methods=['GET'])
def findByName(name):
    return Response().success(UserService().find_by_name(name))

@test.route('/addUser', methods=['POST'])
def addUser():
    try:
        data = request.get_json()
        UserService().addUser(User.decode(data))
    except Exception as e:
        print("用户保存出现错误：{}".format(e))
        return Response().errorMsg(e)
    return Response().success()